import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12

import mdeditor.test.gr 1.0

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("MDEditor")

    MDEditor{
        id:mdeditor
    }

    HtmlViewer{
        id:mdEditorId
        width: parent.width/2 - 10
        height: parent.height
        //color: "grey"
        //anchors.fill: parent
        //anchors.top: comboboxId.bottom
        Component.onCompleted: {
            var default_md = mdeditor.readMarkdownFile()
            setReadOnly(false)
            setTextFormat("PlainText")
            setHtml(default_md)
        }
        onSignalTextChanged: {
            var md = ""
            md = getEditText()
            var mdhtml = mdeditor.md2html(md)
            console.log("md:", md)
            console.log("html:", mdhtml)
            htmlViewerId.setHtml(mdhtml)
        }
    }
    HtmlViewer{
        id:htmlViewerId
        width: parent.width/2 - 10
        height: parent.height
        //color: "grey"
        //anchors.fill: parent
        anchors.left: mdEditorId.right
        Component.onCompleted: {
            setTextFormat("RichText")
            //var md = "# hello world!"
            //var mdhtml = mdeditor.md2html(md)
            //setHtml(mdhtml)
        }
    }

}
